//
//  MyInfoVC.m
//  JinFuThree
//
//  Created by 毛韶谦 on 2018/9/1.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "MyInfoVC.h"
#import "MyInfoCell.h"
#import "MyEducationInfoVC.h"
#import "MyNowAddressVC.h"
#import "MyBaseInfoVC.h"
#import "MyWorkInfoVC.h"
#import "MyRequestTools.h"
#import "MyInfoModel.h"

@interface MyInfoVC ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *mainTableView;
@property (nonatomic, strong) UILabel *headerLabel;
@property(nonatomic,strong)UserCompleteModel *model;

@end

@implementation MyInfoVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"信息完善";
    [self initUI];
    // Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self updateListData];
    
}

- (void)initUI {
    
    self.mainTableView.backgroundColor = ListMaoBackgroundColor;
}


- (void)updateListData {
    
    [self.mainTableView.mj_header endRefreshing];
    
    
    [MyRequestTools getUserInfoCompleteDataSuccess:^(id  _Nullable responseObject) {
        
        if ([[NSString stringWithFormat:@"%@",[responseObject objectForKey:@"code"]] isEqualToString:@"200"]) {
            
            self.model = [UserCompleteModel mj_objectWithKeyValues:[responseObject objectForKey:@"data"]];
            
            [self.mainTableView reloadData];
        }
        
        
    } Failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        
    }];
}


#pragma mark tableView代理方法


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 4;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 55;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 40;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    return 0.01f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    MyInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyInfoCell"];
    if (!cell) {
        cell = [[MyInfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyInfoCell"];
        cell.backgroundColor = [UIColor whiteColor];
    }
    [cell updateDataWithModel:self.model IndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    return self.headerLabel;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor whiteColor];
    return view;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    switch (indexPath.row) {
        case 0:
        {
            MyBaseInfoVC *vc = [[MyBaseInfoVC alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 1:
        {
            MyNowAddressVC *vc = [[MyNowAddressVC alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 2:
        {
            MyWorkInfoVC *vc = [[MyWorkInfoVC alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 3:
        {
            MyEducationInfoVC *vc = [[MyEducationInfoVC alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
            
        default:
            break;
    }
}


- (UITableView *)mainTableView {
    
    if (!_mainTableView) {
        _mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidthMao, ScreenHeight - SafeAreaTopHeight) style:UITableViewStyleGrouped];
        _mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        HFQMJRefreshHeader *header = [HFQMJRefreshHeader headerWithRefreshingTarget:self refreshingAction:@selector(updateListData)];
        _mainTableView.mj_header = header;
        _mainTableView.delegate = self;
        _mainTableView.dataSource = self;
        
        [self.view addSubview:_mainTableView];
    }
    return _mainTableView;
}

- (UILabel *)headerLabel {
    
    if (!_headerLabel) {
        _headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, ScreenWidthMao - 40, 40)];
        _headerLabel.text = @"请完善以下信息, 以便更全面的评估您的信用状况";
        _headerLabel.numberOfLines = 2;
        _headerLabel.font = [UIFont systemFontOfSize:13];
        _headerLabel.textColor = HexColor(0x999999);
        [_headerLabel setTextAlignment:NSTextAlignmentCenter];
        _headerLabel.backgroundColor = HexColor(0xF4F4F4);
        
    }
    return _headerLabel;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
